﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QLChoDiaOc.Process
{
    class ListInfo
    {
        QLChoDiaOcEntities m_entities = new QLChoDiaOcEntities();

        public List<KHACHHANG> ListKhachHang()
        {
            try
            {
                var list = from d in m_entities.KHACHHANGs
                           select d;
                return list.ToList();
            }
            catch
            {
                return null;
            }
        }

        public List<KHACHHANG> ListKhachHang(string MaKH)
        {
            try
            {
                var list = from d in m_entities.KHACHHANGs
                           where d.MaKH == MaKH
                           select d;
                return list.ToList();
            }
            catch
            {
                return null;
            }
        }

        public List<LOAIBANG> ListLoaiBang()
        {
            try
            {
                var list = from d in m_entities.LOAIBANGs
                           select d;
                return list.ToList();
            }
            catch
            {
                return null;
            }
        }

        public List<TOBAO> ListToBao()
        {
            try
            {
                var list = from d in m_entities.TOBAOs
                           select d;
                return list.ToList();
            }
            catch
            {
                return null;
            }
        }

        public List<LOAIDIAOC> ListLoaiDiaOc()
        {
            try
            {
                var list = from d in m_entities.LOAIDIAOCs
                           select d;
                return list.ToList();
            }
            catch
            {
                return null;
            }
        }

        public List<DIAOC> ListDiaOc()
        {
            try
            {
                var list = from d in m_entities.DIAOCs
                           select d;
                return list.ToList();
            }
            catch
            {
                return null;
            }
        }
        
        public List<DIAOC> ListDiaOc(int TinhTrang)
        {
            try
            {
                var list = from d in m_entities.DIAOCs
                           where d.TinhTrang == TinhTrang
                           select d;
                return list.ToList();
            }
            catch
            {
                return null;
            }
        }

        public List<DIAOC> ListDiaOc(string MaDiaOc)
        {
            try
            {
                var list = from d in m_entities.DIAOCs
                           where d.MaDiaOc == MaDiaOc
                           select d;
                return list.ToList();
            }
            catch
            {
                return null;
            }
        }

        public List<DIAOC> ListDiaOc_MaKH(string MaKH)
        {
            try
            {
                var list = from d in m_entities.DIAOCs
                           where d.MaKH == MaKH
                           select d;
                return list.ToList();
            }
            catch
            {
                return null;
            }
        }

        public List<KHACHHANG> ListKhachHangQCBang()
        {
            try
            {
                var list = from khachhang in m_entities.KHACHHANGs
                           from diaoc in m_entities.DIAOCs
                           from dangky in m_entities.PHIEUDANGKies
                           from qcbang in m_entities.QC_BANG
                           where khachhang.MaKH == diaoc.MaKH &&
                                diaoc.MaDiaOc == dangky.MaDiaOc &&
                                dangky.MaDangKy == qcbang.MaDangKy
                           select khachhang;
                return list.ToList();
            }
            catch
            {
                return null;
            }
        }

        public List<KHACHHANG> ListKhachHangQCBao()
        {
            try
            {
                var list = from khachhang in m_entities.KHACHHANGs
                           from diaoc in m_entities.DIAOCs
                           from dangky in m_entities.PHIEUDANGKies
                           from qcbao in m_entities.QC_BAO
                           where khachhang.MaKH == diaoc.MaKH &&
                                diaoc.MaDiaOc == dangky.MaDiaOc &&
                                dangky.MaDangKy == qcbao.MaDangKy
                           select khachhang;
                return list.ToList();
            }
            catch
            {
                return null;
            }
        }

        public List<KHACHHANG> ListKhachHangQCToBuom()
        {
            try
            {
                var list = from khachhang in m_entities.KHACHHANGs
                           from diaoc in m_entities.DIAOCs
                           from dangky in m_entities.PHIEUDANGKies
                           from qctobuom in m_entities.QC_TOBUOM
                           where khachhang.MaKH == diaoc.MaKH &&
                                diaoc.MaDiaOc == dangky.MaDiaOc &&
                                dangky.MaDangKy == qctobuom.MaDangKy
                           select khachhang;
                return list.ToList();
            }
            catch
            {
                return null;
            }
        }

        public List<PHIEUTHU> ListPhieuThuTungThang(int Thang, int Nam)
        {
            try
            {
                var list = from khachhang in m_entities.KHACHHANGs
                           from diaoc in m_entities.DIAOCs
                           from dangky in m_entities.PHIEUDANGKies
                           from phieuthu in m_entities.PHIEUTHUs
                           where khachhang.MaKH == diaoc.MaKH &&
                                diaoc.MaDiaOc == dangky.MaDiaOc &&
                                phieuthu.MaDangKy == dangky.MaDangKy &&
                                phieuthu.NgayThu.Value.Month == Thang &&
                                phieuthu.NgayThu.Value.Year == Nam
                           select phieuthu;
                return list.ToList();
            }
            catch
            {
                return null;
            }
        }

        public List<NHANVIEN> ListNhanVien()
        {
            try
            {
                var list = from d in m_entities.NHANVIENs
                           select d;
                return list.ToList();
            }
            catch
            {
                return null;
            }
        }

        public List<LOAINHANVIEN> ListLoaiNhanVien()
        {
            try
            {
                var list = from d in m_entities.LOAINHANVIENs
                           select d;
                return list.ToList();
            }
            catch
            {
                return null;
            }
        }
    }
}
